Socket
Socket
Sign inDemoInstall

react-required-if

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-required-if

React PropType to conditionally add `.isRequired` based on other props


Version published
Weekly downloads
66K
decreased by-0.61%
Maintainers
1
Weekly downloads
 
Created
Source

react-required-if

React PropType to conditionally add .isRequired based on other props

Install

$ npm install --save react-required-if

Usage

import React, {PropTypes} from 'react';
import requiredIf from 'react-required-if';

export default class Component extends React.Component {
  static propTypes = {
    disabled: PropTypes.bool,
    onClick: requiredIf(PropTypes.func, props => !props.disabled)
  };

  render() {
    return <button onClick={this.props.onClick}>Click Me</button>
  }
}

Result:

import React from 'react';
import {render} from 'react-dom';
import Component from './Component';

render(
  <div>
    <Component onClick={() => {})/> // ok
    <Component disabled={true}/> // ok
    <Component/> // NOooooooo
  </div>,
  document.getElementById('root')
);

FAQs

Package last updated on 11 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc